package com.jiawa.train.member.Controller;


import com.jiawa.train.common.context.LoginMemberContext;
import com.jiawa.train.common.resp.CommonResp;
import com.jiawa.train.common.resp.PageResp;
import com.jiawa.train.member.req.PassengerQueryReq;
import com.jiawa.train.member.req.PassengerSaveReq;
import com.jiawa.train.member.resp.PassengerQueryResp;
import com.jiawa.train.member.service.IPassengerService;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 乘车人 前端控制器
 * </p>
 *
 * @author hrz
 * @since 2025-09-06
 */
@RestController
@RequestMapping("/passenger")
@RequiredArgsConstructor
public class PassengerController {
    private final IPassengerService passengerService;

    @PostMapping("/save")
    public CommonResp<Object> save(@Validated @RequestBody PassengerSaveReq passengerSaveReq) {
        passengerService.save(passengerSaveReq);
        return new CommonResp<>();
    }

    @GetMapping("/query-list")
    public CommonResp<PageResp<PassengerQueryResp>> queryList(@Validated PassengerQueryReq req) {
        if(LoginMemberContext.getMember()!=null){
            req.setMemberId(LoginMemberContext.getMember().getId());
        }
        PageResp<PassengerQueryResp> pa = passengerService.queryList(req);
        return new CommonResp<>(pa);
    }

    @GetMapping("/query-mine")
    public CommonResp<List<PassengerQueryResp>> queryMine() {
        List<PassengerQueryResp> pa = passengerService.queryMine();
        return new CommonResp<>(pa);
    }

    @DeleteMapping("/delete/{id}")
    public CommonResp<Object> delete(@PathVariable Long id) {
        passengerService.delete(id);
        return new CommonResp<>();
    }
}
